package com.softeem.controller;

import com.softeem.entity.Info;
import com.softeem.entity.User;
import com.softeem.model.LayuiPagingResult;
import com.softeem.model.UserParamModel;
import com.softeem.service.StaffService;
import com.softeem.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RequestMapping("/user")
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/isExist")
    @ResponseBody
    private boolean isExist(String param){
        return !userService.isExist(param);
    }

    @RequestMapping("/newUser")
    @ResponseBody
    private boolean newUser(User user){
        return userService.addUser(user);
    }

    @RequestMapping("/login")
    @ResponseBody
    private Map<String, Object> login(@Param("user") User user, @Param("isKeep") String isKeep, @Param("req") HttpServletRequest req, @Param("resp") HttpServletResponse resp){
        Map<String, Object> result = new HashMap<>();
        result.put("state",userService.login(user,isKeep,req,resp));
        return result;
    }

    @RequestMapping("/finish")
    @ResponseBody
    public Map<String, Object> finishOrder(Integer oId){
        Map<String, Object> result = new HashMap<>();
        result.put("state",userService.finishOrder(oId));
        return result;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Map<String, Object> deleteOrder(Integer oId){
        Map<String, Object> result = new HashMap<>();
        result.put("state",userService.deleteOrder(oId));
        return result;
    }

    @RequestMapping("/getUsers")
    @ResponseBody
    public LayuiPagingResult<User> getUsersDynamical(UserParamModel paramModel){
        return userService.getUsersDynamical(paramModel);
    }

    @RequestMapping("/updateUser")
    @ResponseBody
    public Map<String, Object> updateUser(User user){
        Map<String,Object> result = new HashMap<>();
        result.put("state",userService.updateUser(user));
        return result;
    }

    @RequestMapping("/reCheckUser")
    @ResponseBody
    public Map<String, Object> reCheckUser(Integer id){
        Map<String,Object> result = new HashMap<>();
        result.put("state",userService.reCheckUser(id));
        return result;
    }

    @RequestMapping("/deleteUser")
    @ResponseBody
    public Map<String, Object> deleteUser(Integer id){
        Map<String,Object> result = new HashMap<>();
        result.put("state",userService.deleteUserById(id));
        return result;
    }

}
